<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> -->
    <script src="../node_modules/vue/dist/vue.global.js"></script>
    <style>
        .on {
            background: deeppink;
        }
    </style>
</head>

<body>
    <div id="app">
        <!-- 渲染导航部分 -->
        <p>
            <span v-for="(item,index) in navlist" :class="index==actived?'on':''" :key="item.id"
                @click="actived=index">{{item.name}}</span>
        </p>
        <!-- 渲染主体部分 -->
        <div>
            <p v-for="(item,index) in navlist[actived].content" :key="index">
                {{item}}
            </p>
        </div>
    </div>
</body>

</html>
<script>
    const { createApp } = Vue;
    const vm = createApp({
        data() {
            return {
                message1: 'Hello',
                actived: 0, // 设置默认选中的下标
                navlist: [
                    {
                        id: 1,
                        name: '电影',
                        content: ['功夫', '功夫熊猫', '国产凌凌漆']
                    },
                    {
                        id: 2,
                        name: '综艺',
                        content: ['王牌对王牌', '跑男', '最强大脑']
                    },
                    {
                        id: 3,
                        name: '体育',
                        content: ['NBA', 'CBA', '村BA']
                    }
                ]
            }
        }
    }).mount('#app') 
</script>